package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MathGameDetailCommentInputModel;
import com.rjwh.dingdong.client.mvp.presenter.IMathGameDetailCommentInputPresenter;
import com.rjwh.dingdong.client.mvp.view.MathGameDetailCommentInputView;
import com.rjwh.dingdong.client.util.ToastUtil;

/**
 * @author Kay
 * @ClassName DrawBookDetailCommentInputPresenter
 * @Description
 * @date 2016-8-17
 * @history 2016-8-17 author: description:
 */
public class MathGameDetailCommentInputPresenter extends BasePresenter<MathGameDetailCommentInputView> implements IMathGameDetailCommentInputPresenter {
    private MathGameDetailCommentInputModel model;

    public MathGameDetailCommentInputPresenter(Context context, MathGameDetailCommentInputView mMvpView) {
        super(context, mMvpView);
        model = new MathGameDetailCommentInputModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (getMvpView() != null) {
            switch (businessType) {
                case NetConstant.POSTMATHBOOKCOMMENT:
                    getMvpView().dismissLoading();
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS) {
                        getMvpView().updataView();
                    } else {
                        if (!AsStrUtils.isEmpty(mAsResult.getResultMsg())) {
                            ToastUtil.showToast(getContext(), mAsResult.getResultMsg());
                        }
                    }
                    break;
                default:
                    break;
            }
        }

    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    /**
     * 添加游戏评论
     *
     * @param bookid  绘本编码
     * @param content 赏析步骤编码
     */
    @Override
    public void doPostMathBookComment(int bookid, String content) {
        if (isViewAttached()) {
            getMvpView().showLoading();
            model.doPostMathBookComment(bookid, content);
        }
    }
}
